//获取cookie、
const cookie = {
    set(key: string, value: any, expiredays?: number): void {
      if (value) {
        value = JSON.stringify(value);
      }
      const exdate = new Date();
      expiredays && exdate.setTime(exdate.getTime() + (expiredays * 24 * 60 * 60 * 1000));
      document.cookie = key + '=' + value + ((expiredays === undefined) ? '' : ';expires=' + exdate.toUTCString()) + ';path=/' + process.env.VUE_APP_COOKIE // ';domain=ws5353.com';
    },
    get(key: string): any {
      const reg = new RegExp('(^| )' + key + '=([^;]*)(;|$)');
      if (document.cookie.match(reg)?.length) {
        const arr = document.cookie.match(reg)
        return arr && JSON.parse(arr[2])
      }
      return null;
    },
    clear(key: string): void {
      const exp = new Date();
      exp.setTime(exp.getTime() - 1 * 24 * 60 * 60 * 1000);
      const cval = this.get(key);
      if (cval !== null)
        document.cookie = key + '=' + cval + ';expires=' + exp.toUTCString() + ';path=/' + process.env.VUE_APP_COOKIE  //';domain=ws5353.com';
    },
    has(key: string): boolean {
      const isHas = this.get(key)
      return !!isHas
    }
  }
  
  export default cookie